<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class replysController extends Controller
{
    /**
     * 评论列表
     */
    public function getList(Request $request)
    {
        $search = $request->input('search');
        $replys = DB::table('replys')
        ->leftJoin('user_detail', 'replys.uid', '=', 'user_detail.id')
        ->leftJoin('posts', 'replys.pid', '=', 'posts.pid')
        ->where(function($query)use($search){
                if(!empty($search)) {
                    $query->where('replys.content','like',"%$search%");
                }
            })
        ->select('replys.*','user_detail.nickName','posts.content as pcontent')
        ->get();
        $rcount = DB::table('replys')->count();
        return view('admins.feedback-list',['replys'=>$replys,'rcount'=>$rcount,'data'=>$request->all()]);
    }

    /**
     * 获取评论用户基本信息
     */

    public function getUserdetail(Request $request)
    {
        $id = $request->id;
        $userdetail = DB::table('user_detail')
        ->leftJoin('users', 'user_detail.id','=','users.id')
        ->select('user_detail.*','users.score' ,'users.lastLogin')
        ->where('user_detail.id',$id)
        ->first();
        return view('admins.member-show',['userdetail'=>$userdetail]);
    }

    /**
     *下级评论列表
     */
    public function getShow($id)
    {
        $replys = DB::table('replys')
        ->leftJoin('user_detail', 'replys.uid', '=', 'user_detail.id')
        ->leftJoin('posts', 'replys.pid', '=', 'posts.pid')
        ->select('replys.*','user_detail.nickName','posts.content as pcontent')
        ->where('pnid','=',$id)
        ->get();
        return view('admins.nlist',['replys'=>$replys]);
    }

    /**
     * 放入回收站
     */
    public function postDelll(Request $request)
    {
        $id = $request -> id;
        DB::table('replys')
        ->whereIn('id',$id)
        ->update(['status'=>0]);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
